/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package simulator;
import static org.junit.Assert.*;
import org.junit.Test;
/**
 *
 * @author Administrador
 */
public class TestProcessor {
    Processor processor;
    public TestProcessor() {
      processor = Processor.getInstance();  
    }
    
    @Test (expected= AddressOverFlowException.class) 
    public void adressOverFlow()throws AddressOverFlowException{
        String addressA = "FFF";
        String addressB = "001";
        String result = processor.calculateRealAddress(addressA, addressB);
    }
    @Test
    public void validAddressCalculation()throws AddressOverFlowException{
        String result = processor.calculateRealAddress("00F", "007");
        assertTrue(result.equals("16"));
    }
    @Test
    public void validPswArray(){
        processor.PSW = "01";
        char [] test = processor.pswToArray();
        assertTrue(test[7] == '1');
        assertTrue(test[6] == '0');
        assertTrue(test[5] == '0');
        assertTrue(test[4] == '0');
        assertTrue(test[3] == '0');
        assertTrue(test[2] == '0');
        assertTrue(test[1] == '0');
        assertTrue(test[0] == '0');
    }
    
    @Test
    public void testIntegerValueCalculation(){
        int test = processor.integerValue("81");
        assertTrue(test == -1);
        test = processor.integerValue("01");        
        assertTrue(test == 1);
    }
    @Test
    public void testToHexString() throws OperationOverflowException{
        int test = -1;
        assertTrue(processor.toHexString(test).equals("8001"));
    }
    @Test (expected= OperationOverflowException.class) 
    public void testOverflowException()throws OperationOverflowException{
        processor.toHexString(100000000);
        assertTrue(false);
    }
    @Test
    public void testStackOperations() throws StackOverflowException, StackUnderFlowException{
        processor.pushOnStack("0001");
        System.out.println("push successfull");
        String value = processor.popOfStack();
        System.out.println("value = "+value);
        assertTrue(value.equals("0001"));
    }
}
